package com.jbm.core.common.ResponseRecvCallback;

import com.jbm.core.common.ConnectAgent;
import com.jbm.core.common.IoSessionShell;
import com.jbm.core.iface.IAcross;
import com.jbm.core.pb.PBIAcross;

/**
 * Created by root on 17-6-16.
 */
public class KeepliveRRCallback implements ResponseRecvCallback
{
	protected IoSessionShell m_ios;
	protected ConnectAgent m_ca;
	protected boolean m_isclosed;

	protected final Object m_status_mutex = new Object();

	public KeepliveRRCallback()
	{
		m_ios = null;
		m_ca = null;

		m_isclosed = false;
	}


	public KeepliveRRCallback(ConnectAgent ca, IoSessionShell ios)
	{
		this();

		m_ca = ca;
		m_ios = ios;
	}

	public void PushResponse (long start, long cur, PBIAcross.IAcross request, IAcross content, PBIAcross.IAcross response, Object exinfo, boolean isfirst)
	{
		if ( response == null )
			return;

		synchronized (m_status_mutex)
		{
			if ( m_isclosed )
				return;

			m_isclosed = true;

			if ( response.getCode() != 200 )
				m_ios.Sclose(false);
		}
	}
}
